unit modSockUtils;


interface

uses HttpProt, Windows, WinSock, WSocket;


procedure suCopySocketHttpInfos(dst, src: THttpCli);

function suConnecterSurInternetResolveMethod: boolean;
function cdtConnecterSurInternetAPI : Boolean;

function cdtInternetGetConnectedState(lpdwFlags: LPDWORD; dwReserved: DWORD): BOOL; stdcall;

const
  cdt_winetdll = 'wininet.dll';  // Evite d'utiliser la grosse unitée WiniNet pour savoir
                                 // si l'on est connecté à Internet

implementation




function cdtConnecterSurInternetAPI : Boolean;
var
   Connect_status : DWord ;
begin
     Connect_status := 2  + { si vous etes en LAN}
                       1  + { si vous utilisez un modem}
                       4  ; { si vous etes en proxy}
                       
     Result := cdtInternetGetConnectedState(@Connect_status, 0);
end;


function suConnecterSurInternetResolveMethod: boolean;
const Host_Test01 = 'www.google.fr';
      Host_Test02 = 'www.ogame.fr';
var IP: TInAddr;
    xwsData: TWSAData;
begin

    //WSocket_WSAStartup(MAKEWORD($2, $1), xwsData);


    try
        IP := WSocketResolveHost(Host_Test01);

        if IP.S_addr  = 0 then begin
           // l'host Host_Test01 en panne ?
           IP := WSocketResolveHost(Host_Test02);
        end;
        
    except
        Result := false;
        WSocket_WSACleanup;

        exit;
    end;

    //WSocket_WSACleanup;


    if IP.S_addr = 0 then
       Result := false
    else
       Result := true;

end;

procedure suCopySocketHttpInfos(dst, src: THttpCli);
begin
    dst.Agent          := src.Agent;
    dst.Accept         := src.Accept;
    dst.AcceptLanguage := src.AcceptLanguage;

    dst.Proxy          := src.Proxy;
    dst.ProxyPort      := src.ProxyPort;
    dst.ProxyUsername  := src.ProxyUsername;
    dst.ProxyPassword  := src.ProxyPassword;

    
    // fucking relocation
    // on est seulement un proxy
    dst.FollowRelocation  := false;
end;

function cdtInternetGetConnectedState;       external cdt_winetdll name 'InternetGetConnectedState';


end.
